<template>
    <n-form
        style="margin-top: 24px"
        ref="formRef"
        :model="form"
        :rules="rules"
        label-placement="left"
        label-width="auto"
        require-mark-placement="right-hanging"
        size="medium"
    >

        <n-form-item label="会话名称" path="name">
            <n-input v-model:value="form.name" placeholder="请输入会话名称"></n-input>
        </n-form-item>


    </n-form>
</template>

<script setup>
import {onMounted, ref} from 'vue'
import {JBoltApi} from '@/service/request'

const props = defineProps({
    id: String
})

const formRef = ref(null)

const form = ref({
    id: '',
    name: "",

})

const rules = {
    name: {
        required: true,
        message: '请输入会话名称',
        trigger: ['blur', 'input']
    }
}

function submit(callback) {
    formRef.value?.validate(async (errors) => {
        if (!errors) {
            const {result} = await JBoltApi.post('/aiAppSession/update', form.value)
            if (result) {
                callback && callback(form.value)
            }
        }
    })
}

onMounted(async () => {
    if (props.id) {
        const {result ,error} = await JBoltApi.get(`/aiAppSession/getById/${props.id}`)
        if (result){
            form.value = result.data
        }
        if (error){
            console.error(error)
        }
    }
})

defineExpose({
    submit,
    form
})
</script>

<style scoped lang="scss">

</style>